package org.erepublik.company.product;

import java.util.HashMap;

import org.erepublik.company.EProductType;

/**
 * Klasa reprezentujaca szablo dla produktu.
 * Domyslnie wszystke wartosci sa rowne 0
 *
 * @author Kacper Gorski 'Railman' railman85@gmail.com
 */
public class ProductDesign {

    // lista atrybutow
	private HashMap<EProductAttribute, ProductAttribute> map = new HashMap<EProductAttribute, ProductAttribute>();
	private EProductType type;
	
	/**
	 * 
	 * 
	 * @param type
	 */
	public ProductDesign(EProductType type) {
		EProductAttribute[] attributes = EProductAttribute.getAllAttributes(type);
		for (int i=0; i < attributes.length; i++) {
			ProductAttribute attribute = new ProductAttribute(attributes[i], 0);
			map.put(attributes[i], attribute);
		}
		this.type = type;
	}
	
	public EProductType getType() {
		return type;
	}
	
	public int getAttributeValue(EProductAttribute attribute) {
		if (map.get(attribute)==null)
			throw new IllegalArgumentException("Nie znaleziono atrybutu "+attribute+" w produkcie "+type);
		return map.get(attribute).getValue();
	}
	
	public void setAttributeValue(EProductAttribute attribute, int value) {
		if (map.get(attribute)==null)
			throw new IllegalArgumentException("Nie znaleziono atrybutu "+attribute+" w produkcie "+type);
		map.get(attribute).setValue(value);
	}
	
	public String toString() {
		StringBuffer strBuffer = new StringBuffer();
		EProductAttribute[] attributes = EProductAttribute.getAllAttributes(getType()) ;
		for (int i=0; i < attributes.length; i++) {
			strBuffer.append(" ");
			strBuffer.append(attributes[i]);
			strBuffer.append(" ");
			strBuffer.append(getAttributeValue(attributes[i]));
		}
		return strBuffer.toString();
	}
	
}
